package com.example.demo.study.aop;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

@Component
@Aspect
public class BuyAspectJ {
//    @Before("execution(* com.example.demo.study.aop.IBuy.buy(..))  &&within(com.example.demo.study.aop.Boy) ")
//    public void beforeMethod(){
//        System.out.println("男孩女孩都买自己喜欢的东西");
//    }

//    @After("execution(*  com.example.demo.study.aop.IBuy.buy(..))")
//    public void afterMethod()
//    {
//        System.out.println("买完东西之后要付钱");
//    }

//    @AfterReturning("execution(*  com.example.demo.study.aop.IBuy.buy(..))")
//    public void afterReturningMethod()
//    {
//        System.out.println("买完东西之后要付钱");
//    }


//    @Pointcut("execution(*  com.example.demo.study.aop.IBuy.buy(..))")
//    public void drawPoint(){};

    @Pointcut("execution(*  com.example.demo.study.aop.IBuy.gift(..)) && args(price)")
    public void drawGiftPoint(double price){};


//    @Around("drawPoint()")
//    public void around(ProceedingJoinPoint pj) throws Throwable {
//        System.out.println("买前沐浴...");
//        pj.proceed();
//        System.out.println("买后焚香...");
//    }

    @Around("drawGiftPoint(price)")
    public double aroundGift(ProceedingJoinPoint pj,double price) throws Throwable {
        System.out.println("不容易，库库送礼");
        pj.proceed();
        System.out.println("送礼结束");
        return price;
    }

}
